// 获取系统信息 客户端平台，值域为：ios、android
const getSystemInfoSync = () => {
	return uni.getSystemInfoSync().platform
}

// 验证手机号是否正确
const regTel = (tel) => {
    let reg = /^1[3|4|5|7|8]\d{9}$/
    return reg.test(tel)
}

// uniapp APP微信支付
const appWxPay = (options, success, fail) => {
	let orderInfo = {
		appid: options.appid, // 应用ID,
		noncestr: options.noncestr, // 随机字符串,
		package: options.package, // 'Sign=WXPay', // 固定值，以微信支付文档为主,
		partnerid: options.partnerid, // 商户号, 
		prepayid: options.prepayid, // 预支付交易会话ID,  
		timestamp: options.timestamp, // 时间戳,
		sign: options.sign // 签名 // 根据签名算法生成签名,
	}
	uni.requestPayment({  
	    provider: 'wxpay',  
	    // provider: 'alipay',  
	    orderInfo: orderInfo, //微信、支付宝订单数据  
	    success: res => {  
	        // console.log('success:' + JSON.stringify(res))
			success(res)
	    },  
	    fail: err => {  
	        // console.log('fail:' + JSON.stringify(err))
			fail(err)
	    }  
	})
}

// 毫秒时间转换
const msToDate = (msec) => {
    let datetime = new Date(msec);
    let year = datetime.getFullYear();
    let month = datetime.getMonth();
    let date = datetime.getDate();
    let hour = datetime.getHours();
    let minute = datetime.getMinutes();
    let second = datetime.getSeconds();

    let result1 = year +
      '/' +
      ((month + 1) >= 10 ? (month + 1) : '0' + (month + 1)) +
      '/' +
      ((date + 1) < 10 ? '0' + date : date) +
      ' ' +
      ((hour + 1) < 10 ? '0' + hour : hour) +
      ':' +
      ((minute + 1) < 10 ? '0' + minute : minute) +
      ':' +
      ((second + 1) < 10 ? '0' + second : second);

    let result2 = year +
      '/' +
      ((month + 1) >= 10 ? (month + 1) : '0' + (month + 1)) +
      '/' +
      ((date + 1) < 10 ? '0' + date : date);

    return {
        hasTime: result1,
        withoutTime: result2
    };
}

// 数组分隔成每X个一组
const splitArr = (arr, index) => {
	var result = []
	for (let i = 0; i < arr.length; i += index) {
		result.push(arr.slice(i, i + index))
	}
	return result
}

// int转rgb
const converArgbToRgb = (argb) => {
	var rgb = [];
	rgb[0] = (argb & 0xff0000) >> 16;
	rgb[1] = (argb & 0xff00) >> 8;
	rgb[2] = (argb & 0xff);
	return "rgb("+rgb[0]+","+rgb[1]+","+rgb[2]+")";
}
// rgb转int
const converRgbToArgb = (r,g,b) => {
	var color = ((0xFF << 24)|(r << 16)|(g << 8)|b);
	return color;
}
export {
	getSystemInfoSync,
	regTel,
	appWxPay,
	msToDate,
	splitArr
}